<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
%>
<jsp:include page="/web/inc/header"/>
<section>
    <div class="wrap">
        <div id="seach">
            <div id="logo"><a href="http://fenlicx.qinglab.cn" title="再搜索垃圾分类查询">再搜索</a></div>
        </div>
        <nav>
            <div class="classify">
                <ul>
                    <c:forEach items="${requestScope.textures}" var="texture">
                        <li><a href="result2?typeId=${requestScope.typeId}&textureId=${texture.id}" id="${texture.id}"
                               class="texture">${texture.title}</a></li>
                    </c:forEach>
                </ul>
            </div>
            <div data-id="${requestScope.textureId}" id="${requestScope.typeId}" class="content-list"></div>
        </nav>
        <article class="guild">
            <p>如果没有认可的的推荐分类，请点击推荐您认为对的分类，或者提问问题等待其他网站用户回答。</p>
            <div class="link">
                <a href="<%=path%>/web/question/list">问答</a>
                <a href="<%=path%>/web/garbage/addGarbage">添加垃圾</a>
                <a id="addData" data-id="${sessionScope.userinfo.userType.id}" onclick="checkUser()" href="script:void(0);">添加垃圾数据</a>
            </div>
        </article>
    </div>
</section>
<footer>
    <jsp:include page="/web/inc/footer"></jsp:include>
</footer>

<script src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
<script src="<%=path%>/static/js/layui/layui.all.js"></script>
<script>
    //
    var textureId = $(".content-list").data("id");
    var pageNum = 1;
    var typeId = $(".content-list").attr("id");
    //初始化数据，给材质添加点击事件
    $(function () {
        initData(typeId, textureId, pageNum);
    });
    //给页码添加点击事件
    $(function () {
        $(".content-list").on("click", ".pageList a", function () {
            pageNum = $(this).html();
            initData(typeId, textureId, pageNum);
            $(".pageList a[id=" + pageNum + "]").css("color", "#87CEEB");

        });
    })

    //利用ajax更新数据
    function initData(typeId, textureId, pageNum) {
        $.ajax({
            url: "<%=path%>/web/garbage/garbageListData",
            async: false,
            data: {typeId: typeId, textureId: textureId, pageNum: pageNum},
            type: "GET",
            success: function (data) {
                $(".content-list").html(data);
            }
        })
    }

    //判断用户身份
    function checkUser() {
        window.event.returnValue=false;
        var id=$("#addData").data("id");
        if(id=="")
        {
            window.location.href="<%=path%>/web/userinfo/login";
        }
        else
        {
            if(id==3)
            {
                window.location.href="<%=path%>/web/garbage/addData";

            }
            else {
                layer.msg("您没有权限添加数据",{icon:5});
            }
        }
    }
</script>
</body>
</html>
